/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaListaCarnes.java
 *
 * Created on 09-oct-2011, 18:55:41
 */
package Interfaz;

import java.util.*;

import Dominio.*;

/**
 *
 * @author Usuario
 */
public class VentanaListaCarnes extends javax.swing.JFrame {
    
    private SistemaCarne modelo;
    /** Creates new form VentanaListaCarnes */
    public VentanaListaCarnes() {
        initComponents();
    }
    
    public VentanaListaCarnes(SistemaCarne unSistema, boolean caso, String cedula) {
        modelo = unSistema;
        
        initComponents();
        jTxtCedula.setText(cedula);
        if(caso)
            //Médico: todos los niños
            this.jListCarnes.setListData(modelo.getListaNiños().toArray());
        else
            //Padre, madre o tutor: sus hijos
            cargarLista(cedula);
   }


    public void cargarLista(String cedula){
        ArrayList<Niño> listaHijos = modelo.listaHijos(cedula);
        this.jListCarnes.setListData(listaHijos.toArray());//show de la lista de hijos
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jListCarnes = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jTxtCedula = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jBtnOk = new javax.swing.JButton();
        jBtnSalir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBounds(new java.awt.Rectangle(200, 100, 400, 400));
        setMinimumSize(new java.awt.Dimension(300, 350));
        getContentPane().setLayout(null);

        jScrollPane1.setViewportView(jListCarnes);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(30, 60, 220, 200);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(51, 153, 0));
        jLabel1.setText("Lista de Carnés");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(30, 10, 130, 17);

        jTxtCedula.setEditable(false);
        getContentPane().add(jTxtCedula);
        jTxtCedula.setBounds(140, 30, 100, 20);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("CI Usuario:");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(160, 10, 80, 14);

        jBtnOk.setText("Ok");
        jBtnOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnOkActionPerformed(evt);
            }
        });
        getContentPane().add(jBtnOk);
        jBtnOk.setBounds(50, 270, 60, 23);

        jBtnSalir.setText("Salir");
        jBtnSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnSalirActionPerformed(evt);
            }
        });
        getContentPane().add(jBtnSalir);
        jBtnSalir.setBounds(170, 270, 70, 23);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBtnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnSalirActionPerformed
        this.dispose();
    }//GEN-LAST:event_jBtnSalirActionPerformed

    private void jBtnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnOkActionPerformed
       
        Niño niño = (Niño)jListCarnes.getSelectedValue();
        
        VentanaCarne vent = new VentanaCarne(modelo, niño);
        vent.setVisible(true);
        
    }//GEN-LAST:event_jBtnOkActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtnOk;
    private javax.swing.JButton jBtnSalir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JList jListCarnes;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTxtCedula;
    // End of variables declaration//GEN-END:variables
}
